package com.yunding.controller;

import com.yunding.common.BaseResult;
import com.yunding.dto.EmptyClassDTO;
import com.yunding.dto.UpdateClassDto;
import com.yunding.service.EmptyClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.lang.reflect.InvocationTargetException;

/**
 * @author guorui
 * @date 2020-10-03 21:18
 */
@Api("空课API")
@Slf4j
@RestController
@RequestMapping("/class")
public class ClassController {
    @Resource
    private EmptyClassService emptyClassService;

    /**
     * @param emptyClassFrom 空课上传需要填写的信息
     *                       空课上传接口
     */
    @ApiOperation(value = "上传空课信息")
    @PostMapping("/register")
    public BaseResult registerClass(@Valid @RequestBody EmptyClassDTO emptyClassFrom) {
        try {
            emptyClassService.registerClass(emptyClassFrom);
            return BaseResult.ok();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return BaseResult.notOk();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return BaseResult.notOk();
        }
    }
    /**
     * @param emptyClassFrom 空课修改需要填写的信息
     *                       空课修改接口
     */
    @ApiOperation(value = "修改空课信息")
    @PutMapping("/update")
    public BaseResult updateClass(@Valid @RequestBody EmptyClassDTO emptyClassFrom) {
        try {
            emptyClassService.updateClass(emptyClassFrom);
            return BaseResult.ok();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return BaseResult.notOk();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return BaseResult.notOk();
        }
    }
    /**
     *
     */
    @ApiOperation(value = "查询空课接口")
    @GetMapping("/getClass")
    public BaseResult selectClassInfo(UpdateClassDto updateClassDto)  {
        try {
            return BaseResult.ok(emptyClassService.selectClassInfo(updateClassDto));
        } catch (InvocationTargetException e) {
           return BaseResult.notOk();
        } catch (IllegalAccessException e) {
            return BaseResult.notOk();        }
    }
}
